<link rel="stylesheet" href="assets/store/css/goods.css?v=<?= $version ?>">
<link rel="stylesheet" href="assets/common/plugins/umeditor/themes/default/css/umeditor.css">
<link href="assets/layui/css/layui.css" rel="stylesheet">
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">基本信息</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">门票名称 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="ticket[name]"
                                           value="<?= $model['name'] ?>" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">门票分类 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select name="ticket[type]" required
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择门票分类', maxHeight: 400}">
                                        <option value=""></option>
                                        <option value="1" <?php if($model['type']== 1){echo 'selected';}?>>单票</option>
                                        <option value="2" <?php if($model['type']== 2){echo 'selected';}?>>套票</option>
                                    </select>
                                    
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">所属景点 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select name="ticket[scenic_id]" required
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择景点分类', maxHeight: 400}">
                                        <option value=""></option>
                                        <?php if (isset($list)): foreach ($list as $v): ?>
                                            <option value="<?= $v['id'] ?>" <?php if($v['id']== $model['scenic_id']){echo 'selected';}?>><?= $v['scenic_name'] ?></option>
                                            
                                            
                                        <?php endforeach; endif; ?>
                                        
                                    </select>
                                    
                                </div>
                            </div>
                            <div class="am-form-group" id="res" style="display:<?php if($model['type'] != 2){echo 'none';}?>">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">请选择套票集(多选)</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <?php if (isset($allTicket)): $num = 0; foreach ($allTicket as $v): ?>        
                                        <label><input name="ticket[ticket_set][]" type="checkbox" value="<?=$v['id'];?>"  <?php if(in_array($v['id'],$arr)){echo 'checked';}?>>&nbsp<?=$v['name']?></label>&nbsp&nbsp&nbsp
                                        <?php $num++;?>
                                        <?php if($num % 2 == 0){echo '<br>';}?>
                                    <?php endforeach; endif; ?>
                                </div>
                            </div>
                            
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">所属商户 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select name="ticket[store_user_id]" required
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择商户', maxHeight: 400}">
                                        <option value=""></option>
                                        <?php if (isset($user)): foreach ($user as $v): ?>
                                            <option value="<?= $v['store_user_id'] ?>" <?php if($v['store_user_id']== $model['store_user_id']){echo 'selected';}?>><?= $v['user_name'] ?></option>
                                            
                                            
                                        <?php endforeach; endif; ?>
                                        
                                    </select>
                                    
                                </div>
                            </div>

                            
                                   
                                   

                            <!-- 商品单规格 -->
                            <div class="goods-spec-single"
                                 ">
                                
                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">门票价格 </label>
                                    <div class="am-u-sm-9 am-u-end">
                                        <input type="number" class="tpl-form-input" name="ticket[price]"
                                               value="<?= $model['price'] ?>" required>
                                    </div>
                                </div>
                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">起始时间 </label>
                                    <div class="am-u-sm-9 am-u-end ">
                                    <input type="text" name="ticket[time]"
                                           id="time" class="layui-input" value="<?= $model['time'] ?>" 
                                           placeholder="请选择开始时间"  required>
                                           <!-- data-am-datepicker -->
                                           
                                    </div>
                                </div>
                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">当前库存数量 </label>
                                    <div class="am-u-sm-9 am-u-end">
                                        <input type="number" class="tpl-form-input" name="ticket[stock_num]"
                                               value="<?= $model['stock_num'] ?>" required>
                                    </div>
                                </div>
                                
                            </div>

                            <div class="am-form-group am-padding-top">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">文章内容 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <!-- 加载编辑器的容器 -->
                                    <textarea id="container" name="ticket[content]"
                                              type="text/plain"><?= $model['content'] ?></textarea>
                                </div>
                            </div>

                            
                            
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">其他设置</div>
                            </div>
                            
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">门票状态 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="ticket[status]" value="10" data-am-ucheck
                                            <?= $model['status'] == 10 ? 'checked' : '' ?> >
                                        上架
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="ticket[status]" value="20" data-am-ucheck
                                            <?= $model['status'] == 20 ? 'checked' : '' ?> >
                                        下架
                                    </label>
                                </div>
                            </div>
                            
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">门票排序 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" class="tpl-form-input" name="ticket[sort]"
                                           value="<?= $model['sort'] ?>" required>
                                    <small>数字越小越靠前</small>
                                </div>
                            </div>
                       
                            <!-- 表单提交按钮 -->
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary am-btn-sm">提交
                                    </button>
                                </div>
                            </div>

                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<!-- 图片文件列表模板 -->
{{include file="layouts/_template/tpl_file_item" /}}

<!-- 文件库弹窗 -->
{{include file="layouts/_template/file_library" /}}

<script src="assets/common/js/vue.min.js"></script>
<script src="assets/common/js/ddsort.js"></script>
<script src="assets/common/plugins/umeditor/umeditor.config.js?v=<?= $version ?>"></script>
<script src="assets/common/plugins/umeditor/umeditor.min.js"></script>
<script src="assets/store/js/goods.spec.js?v=<?= $version ?>"></script>
<script src="assets/layui/layui.js"></script>
<!-- <script src="assets/store/js/jquery.2.1.4.min.js"></script> -->
<script>
    $(function () {

       // 富文本编辑器
       UM.getEditor('container', {
            initialFrameWidth: 375 + 15,
            initialFrameHeight: 600
        });

       
        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm();
       
    });
</script>
<script>
    layui.use('laydate', function(laydate){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
            elem: '#time', //指定元素
            type:'time',
            range: true,
            
        });
    });
    /**
     *  景点下拉框事件
     */
    $("[name='ticket[scenic_id]']").change(function(){
        var scenic_id = $(this).val();
        console.log(scenic_id);
        var type = $("[name='ticket[type]']").val();
        console.log(type);
        
        if(type == null || type == ''){
            
            //layer.msg('请先选择门票分类！',{icon:5});
            
            return false;
        }else if(type == 2){
            Ajax(scenic_id);
        }
        
                       
    })
    /**
     *  分类下拉框事件
     */
    $("[name='ticket[type]']").change(function(){
       var type = $(this).val();
       var scenic_id = $("[name='ticket[scenic_id]']").val();           
        if(type !=  2){
            $('#res').css("display","none");
        }else if(type == 2 &&  scenic_id != ''){
            Ajax(scenic_id);
        }           
    })
    /**
     *  发送ajax请求
     */
    function Ajax(scenic_id){
        $.ajax({
                url:'store/scenic.ticket/getTicketSet?scenic_id=' + scenic_id,
                type:'GET',
                dataType:'JSON',
                success:function(res){
                    
                    if(res.code == 1){
                        var arr = Object.keys(res.data);

                        if(arr.length == 0){
                            var list = '<p style="margin-left:200px; color:red;">*该景点暂无出售的单票，请先<a href="<?= url('scenic.ticket/add') ?>">添加</a>*</p>';
                            $('#res').show().html(list);
                            return false;   
                        } 
                        var list = '<div class="am-u-sm-9 am-u-end" style="margin-left:45px;"><label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">请选择套票集(多选) </label><div class="am-u-sm-9 am-u-end">';
                        $.each(res.data,function(index,value){
                            list += '<label><input name="ticket[ticket_set][]" type="checkbox" value="'+value.id + '" />&nbsp' + value.name + '</label>&nbsp&nbsp&nbsp&nbsp&nbsp';
                            if (index % 2 == 1 ){
                                list += '<br>';
                            }
                        })
                        list+='</div></div>';
                        $('#res').show().html(list);
                    }
                }
            })
    }
</script>